package com.zhang.family_doctor.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.family_doctor.dto.PaymentDto;
import com.zhang.family_doctor.dto.SignUpDetailsDto;
import com.zhang.family_doctor.dto.SignUpDto;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.entity.SignUp;
import com.zhang.family_doctor.service.SignUpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 签约模块
 */
@RestController
@RequestMapping("/signUp")
@Slf4j
@Api(tags = "签约模块")
public class SignUpController {

    @Autowired
    private SignUpService signUpService;

    @ApiOperation("居民提交申请签约")
    @PostMapping("/ApplySigning")
    public R<String> applySigning(@RequestBody SignUp signUp, HttpServletRequest request){
        log.info("居民提交申请签约：{}",signUp);
        return signUpService.applySigning(signUp,request);
    }

    @ApiOperation("审核通过签约申请")
    @PostMapping("/doctorAudit")
    public R<String> doctorAudit(SignUp signUp,HttpServletRequest request){
        log.info("审核通过签约申请：{}",signUp);
        return signUpService.doctorAudit(signUp,request);
    }

    @ApiOperation("驳回申请")
    @PostMapping("/reject")
    public R<String> reject(SignUp signUp , HttpServletRequest request){
        log.info("驳回申请：{}",signUp);
        return signUpService.reject(signUp,request);
    }

    @ApiOperation("续约申请")
    @PostMapping("/renewalApplication")
    public R<String> renewalApplication(@RequestBody SignUp signUp){
        log.info("续约申请：{}",signUp);
        return signUpService.renewalApplication(signUp);
    }

    @ApiOperation("通过续约申请")
    @PostMapping("/renewalApproved")
    public R<String> renewalApproved(SignUp signUp,HttpServletRequest request){
        log.info("通过续约申请：{}",signUp);
        return signUpService.renewalApproved(signUp,request);
    }

    @ApiOperation("驳回续约申请")
    @PostMapping("/rejectRenewalApplication")
    public R<String> rejectRenewalApplication(SignUp signUp , HttpServletRequest request){
        log.info("驳回续约申请：{}",signUp);
        return signUpService.rejectRenewalApplication(signUp,request);
    }

    @ApiOperation("居民端查看签约详情")
    @GetMapping("/getSignUpDetails")
    public R<SignUpDetailsDto> getSignUpDetails(Integer id){
        log.info("居民端查看签约详情：{}",id);
        return signUpService.getSignUpDetails(id);
    }

    @ApiOperation("居民端查看签约记录")
    @GetMapping("/getSignUp")
    public R<List<SignUp>> getSignUp(HttpServletRequest request){
        log.info("居民端查看签约记录：");
        return signUpService.getSignUp(request);
    }

    @ApiOperation("分页查询待处理签约")
    @GetMapping("/getPending")
    public R<PageInfo<SignUpDto>> getPending(SignUpDto signUpDto){
        log.info("分页查询待处理签约:{}",signUpDto);
        return signUpService.getPending(signUpDto);
    }

    @ApiOperation("调用微信练习中的微信支付接口")
    @PostMapping("/weChatPayment")
    public R<String> weChatPayment(@RequestBody PaymentDto paymentDto){
        log.info("调用微信练习中的微信支付接口");
        return signUpService.weChatPayment(paymentDto);
    }

    //调用第三方接口
    @ApiOperation("调用微信练习中的支付宝支付接口")
    @PostMapping("/alipayPayment")
    public R<String> alipayPayment(@RequestBody PaymentDto paymentDto){
        log.info("调用微信练习中的支付宝支付接口");
        return signUpService.alipayPayment(paymentDto);
    }

    //回调接口
    @ApiOperation("支付成功的接口")
    @PostMapping("/paymentSucceeded")
    public R<String> paymentSucceeded(@RequestBody PaymentDto paymentDto){
        log.info("支付成功的接口：{}",paymentDto);
        return signUpService.paymentSucceeded(paymentDto);
    }

}
